# Maintainer: Christian Hesse <mail@eworm.de>
# Contributor: mickele <mimocciola at yahoo dot com> (librecad-git PKGBUILD)
# Contributor: Ilmari Repo <ilmari at gmail dot com> (librecad-svn PKGBUILD)
# Contributor: GazJ Gary James <garyjames82 at gmail dot com> (CADuntu PKGBUILD)

pkgname=librecad
pkgver=2.2.0
pkgrel=1
pkgdesc='A 2D CAD drawing tool based on the community edition of QCad'
arch=('loong64' 'x86_64')
url='https://www.librecad.org/'
license=('GPL')
depends=('qt5-base' 'qt5-svg' 'libxcb' 'muparser')
makedepends=('qt5-tools' 'boost' 'imagemagick' 'librsvg')
conflicts=('librecad-git')
replaces=('librecad-svn' 'caduntu' 'caduntu-svn')
source=("${pkgname}-${pkgver}.tar.gz::https://github.com/LibreCAD/LibreCAD/archive/${pkgver}.tar.gz")
sha256sums=('dfce6f290b89707a0717789aa0cdea4ca5a96685fa0e65cfc49d70166bd182f2')

build() {
	cd "${srcdir}/LibreCAD-${pkgver}"

	# fix version string
	sed -i "/^SCMREVISION/c SCMREVISION=\"${pkgver}\"" librecad/src/src.pro

	qmake-qt5 librecad.pro

	# fix include path... this is an issue with gcc 6.1.1 and qmake-qt5...
	make qmake_all
	sed -i '/INCPATH/s|-isystem /usr/include ||' librecad/src/Makefile

	make
}

package() {
	cd "${srcdir}/LibreCAD-${pkgver}"

	# executables
	install -D -m0755 unix/librecad "${pkgdir}/usr/bin/librecad"
	install -D -m0755 unix/ttf2lff "${pkgdir}/usr/bin/ttf2lff"

	# desktop file and man pages
	install -D -m0644 desktop/librecad.desktop "${pkgdir}/usr/share/applications/librecad.desktop"
	install -D -m0644 desktop/librecad.1 "${pkgdir}/usr/share/man/man1/librecad.1"

	# documentation
	install -D -m0644 librecad/support/doc/README "${pkgdir}/usr/share/doc/librecad/index.README"
	install -D -m0644 librecad/support/doc/index.html "${pkgdir}/usr/share/doc/librecad/index.html"
	install -D -m0644 librecad/support/doc/style.css "${pkgdir}/usr/share/doc/librecad/style.css"
	install -D -m0644 librecad/support/doc/img/librecadlogo.png "${pkgdir}/usr/share/doc/librecad/img/librecadlogo.png"

	# icons
	for SIZE in 16 24 32 48 64 96 128; do
		# set modify/create for reproducible builds
		convert -scale ${SIZE} +set date:create +set date:modify \
			desktop/graphics_icons_and_splash/Icon\ LibreCAD/Icon_Librecad.svg \
			"${srcdir}"/librecad.png
		install -D -m0644 "${srcdir}"/librecad.png "${pkgdir}/usr/share/icons/hicolor/${SIZE}x${SIZE}/apps/librecad.png"
	done
	install -D -m0644 desktop/graphics_icons_and_splash/Icon\ LibreCAD/Icon_Librecad.svg "${pkgdir}/usr/share/icons/hicolor/scalable/apps/librecad.svg"

	# resources
	mkdir -p "${pkgdir}/usr/share/librecad/"
	cp -r unix/resources/{library,patterns,fonts,qm} "${pkgdir}/usr/share/librecad/"
}

